import java.util.TreeSet;

class ExamRoom {
    TreeSet<Integer> set;
    int n;
    public ExamRoom(int n) {
        this.n = n;
        set = new TreeSet<>();
    }

    public int seat() {
        if (set.size() == 0) {
            set.add(0);
            return 0;
        }
        int l = set.first(),index = 0,wid = set.first();
        for (int i : set) {
            if (wid < (i - l) / 2) {
                wid = (i - l) / 2;
                index = (i + l) / 2;
            }
            l = i;
        }
        int wi = n - 1 - set.last();
        if (wid < wi) index = n - 1;
        set.add(index);
        return index;
    }

    public void leave(int p) {
        set.remove(p);
    }
}